using Digitalmes.Domain.Entities.Mes.Processes;

namespace Digitalmes.Application.Mes.Processes.StepMaterials.Commands;

/// <summary>
/// 工序物料创建命令。
/// </summary>
public sealed record CreateStepMaterialCommand(ProcStepMaterialDto StepMaterial) : IRequest<IResult<bool>>;

internal sealed class CreateStepMaterialCommandHandler(IRepository<ProcStepMaterial> repo) : IRequestHandler<CreateStepMaterialCommand, IResult<bool>>
{
    public async Task<IResult<bool>> Handle(CreateStepMaterialCommand request, CancellationToken cancellationToken)
    {
        var mateial = request.StepMaterial.Adapt<ProcStepMaterial>();
        var ok = await repo.InsertAsync(mateial, cancellationToken);
        return Result.From(ok);
    }
}
